// Author: Ivan Chau
package uk.ac.cam.kcic2.scene;

import java.util.ArrayList;

import uk.ac.cam.kcic2.math.Matrix4;
import uk.ac.cam.kcic2.math.Transform;
import uk.ac.cam.kcic2.math.Vector3D;

public abstract class Primitives extends SceneObject{
	
	protected final Matrix4 localToWorldPointTransform;
	protected final Matrix4 localToWorldNormalTransform;
	protected final Matrix4 worldToLocalPointTransform;
	public final Matrix4 worldToLocalNormalTransform;
	//protected final Scale localToWorldScaleTransform;
	public final Vector3D worldCentre;

	public Primitives(ArrayList<Transform> trans, ColourCoeffs coeffs,
			CompoundObject father) {
		super(trans, coeffs, father);
		
		Matrix4 pointWorldTransform = this.localToParentPointTransform;
		Matrix4 normalWorldTransform = this.localToParentNormalTransform;		
		Matrix4 pointLocalTransform = this.parentToLocalPointTransform;	
		Matrix4 normalLocalTransform = this.parentToLocalNormalTransform;		
		//Scale scaleTransform = this.localToParentScaleTransform;
		CompoundObject dad = parent;
		
		while (dad != null){
			pointWorldTransform = dad.localToParentPointTransform.mult(pointWorldTransform);
			normalWorldTransform = dad.localToParentNormalTransform.mult(normalWorldTransform);
			pointLocalTransform = pointLocalTransform.mult(dad.parentToLocalPointTransform);
			normalLocalTransform = normalLocalTransform.mult(dad.parentToLocalNormalTransform);
			//scaleTransform = scaleTransform.mult(dad.localToParentScaleTransform);
			
			dad = dad.parent;
		}
		
		localToWorldPointTransform = pointWorldTransform;
		localToWorldNormalTransform = normalWorldTransform;
		worldToLocalPointTransform = pointLocalTransform;
		worldToLocalNormalTransform = normalLocalTransform;
		
		//localToWorldScaleTransform = scaleTransform;		
		worldCentre = localToWorldPointTransform.mult(centre);
	}
	
	//public abstract IntersectionInfo getIntersection(Ray ray);	
}
